package com.yegs.jltqc.config;


import com.yegs.jltqc.VO.BaseUser;
import com.yegs.jltqc.common.StoreException;

public class ConcurentCache {

    private static ThreadLocal<BaseUser> userThread = new ThreadLocal<BaseUser>();



    //从当前线程变量中获取用户信息
    public static BaseUser getLoginUser() {
        BaseUser user = userThread.get();
        return user;
    }

    //为当前的线程变量赋值上用户信息
    public static void setLoginUser(BaseUser user) {
        userThread.set(user);
    }

    public static String getUserName(){
        BaseUser user = userThread.get();
        if(user == null){
            //throw new StoreException("登录过期!");
            return "admin";
        }
        return user.getUsername();
    }

    //移除当前线程的存的变量
    public void remove() {
        this.userThread.remove();
    }

}
